<%@page import="java.awt.print.Printable"%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
<head>
<title>_${customer.customerName}_上架</title>
<script type="text/javascript">

  $(function() {
       //如果上架已经完成，隐藏操作按钮
	   var status='${task.status}';
	   if(status!='token' && status!='doing'){
	      $("button").hide();   
	   }
  });
  
  function keydown(){
	  $("#msg").html("");
  }
  
  function skuChange(){
	  $("#txt_stockCode").val('');
	  $("#txt_stockCode").focus();
  }
  
  function stockCodeChange(){
	  $("#txt_boxCode").val('');
	  $("#txt_boxCode").focus();
  }
  
  function boxCodeChange(){
  
      var sku=$("#txt_sku").val().trim();
	  var stockCode=$("#txt_stockCode").val().trim();
	  var boxCode=$("#txt_boxCode").val().trim();
	  
	  if(sku.length==0){
		  $("#msg").css("color","red");
		  $("#msg").html("请录入/扫描SKU!");
		  $("#txt_sku").focus();
	  }
	  
	  if(stockCode.length==0){
		  $("#msg").css("color","red");
		  $("#msg").html("请录入/扫描库位编码!");
		  $("#txt_stockCode").select();
		  $("#txt_stockCode").focus();
	  }
	  
	  if(boxCode.length==0){
		  $("#msg").css("color","red");
		  $("#msg").html("请录入/扫描箱编码!");
		  $("#txt_boxCode").focus();
	  }
	  
	  var uptaskCode='${task.taskCode}';
	  
      $.ajax({
			type:'post',
			url:'${ctx}/v2_instorageUp/ajaxUp_single',
			data:{
				uptaskCode:uptaskCode,
				sku:sku,
				stockCode:stockCode,
				boxCode:boxCode,
			},
			dataType:'json',
			success:function(data) {
				var msg=data.msg;
			    if( msg=='continue'){
				    $("#msg").css("color","green");
		            $("#msg").html("上架成功.");
		            
		            $("#txt_sku").val('');
		            $("#txt_stockCode").val('');
		            $("#txt_boxCode").val('');
		            $("#txt_sku").focus();
		            
		            
		            var itemList=data.itemList;
                    $("#item").html('');
         	        var str='';
			        $.each(itemList,function(i,item){
			    	   str+="<tr>";
			    	   str+="<td>"+item.sku+"</td>";
			    	   str+="<td>"+item.num+"</td>";
			    	   str+="<td>"+item.upNum+"</td>";
			    	   
			    	   var upStatus=item.upStatus;
			    	   var upStatusStr;
			    	   if(upStatus=='unup'){
			    	      upStatusStr='<font color=red>未上架</font>';
			    	   }else if(upStatus=='uping'){
			    	      upStatusStr='<font color=blue>上架中...</font>';
			    	   }else if(upStatus=='up'){
			    	      upStatusStr='<font color=green>已上架</font>';
			    	   }
			    	   str+="<td>"+upStatusStr+"</td>";
			    	   
			    	   str+="</tr>";
			        });
			       
			       $("#item").html(str);
		            
		            
		            
			    }
			    else if(msg=='finishing'){
			        $("#msg").css("color","green");
		            $("#msg").html("上架成功.");
		            
		            window.alert("完成上架！！请按“确定”继续。"); 
				    location.href='${ctx}/v2_instorageUp/toUpTaskListPage';
		            
			    }
			    else if(msg=='S009'){
			         $("#msg").css("color","red");
		            $("#msg").html("入库单已取消！");
		            
		            $("#txt_sku").val('');
		            $("#txt_stockCode").val('');
		            $("#txt_boxCode").val('');
		            $("#txt_sku").focus();
		            
			    }
			    else{
			        $("#msg").css("color","red");
		            $("#msg").html("验证不成功！");
		            
		            $("#txt_sku").val('');
		            $("#txt_stockCode").val('');
		            $("#txt_boxCode").val('');
		            $("#txt_sku").focus();
			    }
			},
			error:function() {
				alert("网络繁忙，请稍后重试...");
			}
	   });
  }
  
</script>
</head>

<body>
<section class="content">

	<table id="contentTable" class="table  table-bordered table-condensed">
	    <thead>
			<th style="vertical-align: middle; color: white; " colspan="13" bgcolor="#3c8dbc"><i class="fa fa-barcode"/>  扫描上架（散装）</th>
		</thead>
		
		<tr>
		    <td colspan="4"> 
		       <span style="margin-left: 10px;">SKU编码:</span>
		       <input id="txt_sku" type="text" onchange="skuChange();"  onkeydown="keydown();"/>
		       <span style="margin-left: 10px;">库位编码:</span>
		       <input id="txt_stockCode" type="text" onchange="stockCodeChange();"/>
		       <span style="margin-left: 10px;">箱编码:</span>
		       <input id="txt_boxCode" type="text" onchange="boxCodeChange();"/>
		       
		       <span style="margin-left:12px; margin-top: 10px; color: red;font-weight: bold;" id="msg"></span>
		    </td>
		</tr>
		
		<tr>
		    <td>库位</td>
		    <td>箱位</td>
		    <td>数量</td>
		    <td>操作</td>
		</tr>
		<tr name="exist" id="info">
		</tr>
		
		<tr name="noexist">
		   <td colspan="4" height="50" style="vertical-align:middle; text-align: center;color: gray;font-size: 20px;">无数据</td>
		</tr>
		
	</table>
	
	
	<!-- 商品数据 -->
	<table class="table table-striped table-bordered table-condensed" style="margin-top: 0px;">
		<thead>
			<th style="vertical-align: middle; color: white; " colspan="13" bgcolor="#3c8dbc"><i class="fa fa-th-list"/> 商品数据</th>
		</thead>
		<thead><tr>
			    <th style="width: 150px;">SKU</th>
			    <th style="width: 150px;">数量</th>
			    <th style="width: 150px;">已上架数量</th>
			    <th>上架状态</th>
			</tr></thead>
		<tbody id="item">
		<c:forEach items="${itemList}" var="t" varStatus="i">
			<tr>
			   <td>${t.sku}</td>
			   <td>${t.num}</td>
			   <td>${t.upNum}</td>
			   <td>
			       <c:if test="${t.upStatus eq 'unup'}"> <font color=red>未上架           </font></c:if>
			       <c:if test="${t.upStatus eq 'uping'}"><font color=blue>上架中...</font></c:if>
			       <c:if test="${t.upStatus eq 'up'}">   <font color=green>已上架      </font></c:if>
			   </td>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	
</section>	
</body>
</html>
